This document
This document
import pandas as pd # Import data from R df = r.cryptodata # Show data df
## pair symbol ask_1_price date_time_utc ## 0 ETHUSD ETH 596.699 2020-12-06 00:00:01 ## 1 ETHUSD ETH 605.099 2020-12-06 01:00:01 ## 2 ETHUSD ETH 603.294 2020-12-06 02:00:01 ## 3 ETHUSD ETH 599.659 2020-12-06 03:00:01 ## 4 ETHUSD ETH 596.769 2020-12-06 04:00:01 ## ... ... ... ... ... ## 1951 ETHUSD ETH 355.851 2020-09-09 20:00:38 ## 1952 ETHUSD ETH 352.805 2020-09-09 21:00:39 ## 1953 ETHUSD ETH 352.934 2020-09-09 22:00:39 ## 1954 ETHUSD ETH 355.471 2020-09-09 23:00:38 ## 1955 ETHUSD ETH 357.844 NaT ## ## [1956 rows x 4 columns]
import numpy as np
df['Price Percentile'] = np.where(df['ask_1_price'] > np.percentile(df['ask_1_price'], 50),
'upper 50th percentile of prices',
'lower 50th percentile of prices')
# Show modified dataframe:
df
## pair symbol ... date_time_utc Price Percentile ## 0 ETHUSD ETH ... 2020-12-06 00:00:01 upper 50th percentile of prices ## 1 ETHUSD ETH ... 2020-12-06 01:00:01 upper 50th percentile of prices ## 2 ETHUSD ETH ... 2020-12-06 02:00:01 upper 50th percentile of prices ## 3 ETHUSD ETH ... 2020-12-06 03:00:01 upper 50th percentile of prices ## 4 ETHUSD ETH ... 2020-12-06 04:00:01 upper 50th percentile of prices ## ... ... ... ... ... ... ## 1951 ETHUSD ETH ... 2020-09-09 20:00:38 lower 50th percentile of prices ## 1952 ETHUSD ETH ... 2020-09-09 21:00:39 lower 50th percentile of prices ## 1953 ETHUSD ETH ... 2020-09-09 22:00:39 lower 50th percentile of prices ## 1954 ETHUSD ETH ... 2020-09-09 23:00:38 lower 50th percentile of prices ## 1955 ETHUSD ETH ... NaT lower 50th percentile of prices ## ## [1956 rows x 5 columns]